#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAXH	(1000000 + 1)

typedef unsigned long long int ull;

int main() {
	int n, m, i, k, maxz = 0, maxp = 0;
	ull *t, v = 0;
	
	scanf("%d %d", &n, &m);
	t = malloc(sizeof(ull) * MAXH);
	memset(t, 0, sizeof(ull) * MAXH);
	
	for(i = 0; i < n; i++) {
		scanf("%d", &k);
		if(k > maxz)
			maxz = k;
		t[k]++;
	}
	k = 0;
	for(i = maxz; i > 0; i--) {
		if(t[i] > 0) {
			k += t[i];
		}
		t[i] = k;
	}
	for(i = 2; i <= maxz; i++) {
		t[i] += t[i - 1];
	}

	t[0] = 0;
	for(i = 0; i < m; i++) {
		scanf("%d", &k);
		if(k > maxp)
			maxp = k;
		v += t[k];
	}
	if(maxz == maxp)
		printf("%llu\n", v);
	else
		printf("NIE\n");
	
	return 0;
}
